﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data.SqlClient;
using System.Data;


namespace Web.Settle
{
    public partial class CheckOut : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataBind("");
            }
        }
        private void DataBind(string WBName)
        {


            //获取存粮信息
            StringBuilder strSql = new StringBuilder();
            strSql.Append("  SELECT A.ID,B.ID as WBID, B.strName AS WBName,C.ID as VarietyID, C.strName AS VarietyName,A.numStorage");
            strSql.Append("  FROM dbo.SA_VarietyStorage A INNER JOIN WB B ON A.WBID=B.ID");
            strSql.Append("  INNER JOIN dbo.StorageVariety C ON A.VarietyID=C.ID");
            strSql.Append("  ");


            if (WBName.ToString().Trim() != "")
            {
                strSql.Append("   WHERE B.strName = '" + WBName + "'");
            }



            DataTable dt = SQLHelper.ExecuteDataTable(strSql.ToString());
            Repeater1.DataSource = dt;
            Repeater1.DataBind();

        }

        public string GetVarietyLevel(object objVarietyName)
        {
            
            StringBuilder strSql = new StringBuilder();
            strSql.Append("  SELECT TOP 1 C.strName");
            strSql.Append("  FROM dbo.StorageVariety A INNER JOIN dbo.StorageVarietyLevel_L B ON B.VarietyID=A.ID");
            strSql.Append("  INNER JOIN dbo.StorageVarietyLevel_B C ON B.VarietyLevelID=C.ID ");
            strSql.Append("  WHERE A.strName='"+objVarietyName+"'");
            return SQLHelper.ExecuteScalar(strSql.ToString()).ToString() ;
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            object objWB = SQLHelper.ExecuteScalar(" SELECT  COUNT(ID) FROM dbo.WB WHERE strName ='" + txtWBID.Value.Trim() + "'");
            if (Convert.ToInt32(objWB) <= 0)
            {
                Fun.Alert("您查询的网点不存在");
                return;
            }
            DataBind(txtWBID.Value);
        }

    

        public string OutPut(object objID, object objWBID,object objVarietyID)
        {
            bool Authority = common.GetAuthority(Session["UserGroup_Name"], Session["ID"], Request.QueryString["MenuID"], "E");
            if (Authority)
            {
                return " <a href='/Settle/CheckOutDetail.aspx?ID="+objID+"&WBID="+objWBID+"&VarietyID="+objVarietyID+"'>出库</a>";
            }
            else
            {
                return " <a href='#' disabled='disabled'>出库</a> ";
            }
        }
        
    }
}